package com.util;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

import java.net.URL;

/**
 * @author Ricky
 * @date 2020-8-12 15:22
 */
public class FxmlUtil {
    public static URL getURLByFxmlName(String fxmlName) {
        String fxmlFilePath = PathUtil.resolve("fxml", fxmlName + ".fxml");
        return PathUtil.getURL(fxmlFilePath);
    }

    public static Parent getParent(String fxmlName) throws Exception {
        URL resource = getURLByFxmlName(fxmlName);
        if (resource == null) {
            throw new Exception("FXML文件【" + fxmlName + "】未找到");
        }
        return FXMLLoader.load(resource);
    }
}
